package com.ttms.dao.impl;
import com.ttms.dao.SaleDao;
import com.ttms.pojo.Sale;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.List;

public class SaleDaoImpl extends BaseDao implements SaleDao {


    @Override
    public int addSale(Sale sale) {

        String sql = "insert into sale(user_id,sale_time,sale_payment,sale_change,sale_type,sale_status) values(?,?,?,?,?,?)";

        return update(sql,sale.getUser_id(),sale.getSale_time(),sale.getSale_payment(),sale.getSale_change(),sale.getSale_type(),sale.getSale_status());
    }

    @Override
    public int deleteSaleById(Integer id) {
        String sql = "delete from sale where sale_ID = ?";
        return update(sql,id);
    }

    @Override
    public int updateSale(Sale sale) {
        String sql = "update sale set sale_ID=?,user_id=?,sale_time=?,sale_payment=?,sale_change=?,sale_type=?,sale_status=? where sale_ID = ?";
        return update(sql,sale.getSale_id(),sale.getUser_id(),sale.getSale_time(),sale.getSale_payment(),sale.getSale_change(),sale.getSale_type(),sale.getSale_status(),sale.getSale_id());
    }

    @Override
    public Sale querySaleById(Integer id) {
        String sql = "select * from sale where user_id=?";

        return queryForOne(Sale.class, sql,id);
    }

    @Override
    public List<Sale> findSaleById(String id) {
        String sql = "select * from sale where user_id=?";
        return queryForList(Sale.class, sql,id);
    }

    @Override
    public List<Sale> findSaleId(int user_id, Timestamp sale_time, BigDecimal sale_payment, BigDecimal sale_change, int sale_type, int sale_status) {
        String sql = "select * from sale where user_id = ? and sale_type=? and sale_status = ? ";

        return queryForList(Sale.class,sql,user_id,sale_type,sale_status);
    }

    @Override
    public List<Sale> querySales() {
        return null;
    }

    @Override
    public Integer queryForPageTotalCount() {
        return null;
    }

    @Override
    public List<Sale> queryForPageItems(int begin, int pageSize) {
        return null;
    }

    @Override
    public Sale querySaleByUserId(int user_id) {
        String sql =" select * from sale where user_id = ? ";
        return queryForOne(Sale.class,sql,user_id);
    }
}
